package com.feihao.zhou.TCP.demo02;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",10088);

        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("你好啊，服务器".getBytes());

        socket.shutdownOutput();  //使用socket的shutdownOutPut方法，关闭网络写入流，同时给服务器结束标志

        /*outputStream.close();*/  //在这里关流会导致后续的socket不呢个使用！！！

        //读取服务器的回写内容：
        InputStream inputStream = socket.getInputStream();
        int len;
        byte[] bytes = new byte[1024];
        while ((len=inputStream.read(bytes))!=-1){
            System.out.println(new String(bytes,0,len));
        }

        socket.close();
        outputStream.close();
        inputStream.close();
    }
}
